// HUD SYSTEM

Oldrank = "none"
Killer = nil
Fl = 0
Bool = false
surface.CreateFont("Quake1", {font = "Arial",
                                    size = 75,
                                    weight = 200})
surface.CreateFont("QuakeHud",{font = "Arial",
                                    size = 350,
                                    weight = 3000})
surface.CreateFont("Quaketext",{font = "Arial",
                                    size = 35,
                                    weight = 50})




function GM:ShowAttacker()
if(!LocalPlayer():Alive()) then return end

end
// self:SmallStats()
//self:SetupHud()


function GM:SmallStats()
tab = {}
for k,v in ipairs(player.GetAll()) do
	table.insert(tab, {Frags = v:Frags(),Play = v})
end

table.SortByMember( tab, "Frags" )


if(!LocalPlayer():Alive()) then return end


surface.SetDrawColor(255,255,255,10)
surface.DrawRect(ScrW()-ScrW()/5,ScrH()-ScrH()/5,ScrW()/6,50)

surface.SetDrawColor(42,42,42,255)
surface.DrawOutlinedRect((ScrW()-ScrW()/5)+((ScrW()/6)/3),ScrH()-ScrH()/5,((ScrW()/6)/3),50)
draw.DrawText( "N/A", "Quaketext",(ScrW()-ScrW()/5)+((ScrW()/6)/3)-80,(ScrH()-ScrH()/5)+10, Color(255,255,255,255 ), TEXT_ALIGN_LEFT )
if(LocalPlayer():GetRank() == "1st") then
draw.DrawText( ""..(LocalPlayer():Frags()).."", "Quaketext",(ScrW()-ScrW()/5)+((ScrW()/6)/3)+40,(ScrH()-ScrH()/5)+10, Color(255,255,255,255 ), TEXT_ALIGN_LEFT )
draw.DrawText( ""..(tab[2].Play:Frags()).."", "Quaketext",(ScrW()-ScrW()/5)+((ScrW()/6)/3)+150,(ScrH()-ScrH()/5)+10, Color(255,255,255,255 ), TEXT_ALIGN_LEFT )
elseif(LocalPlayer():GetRank() == "none" or LocalPlayer():GetRank() == "3rd" or LocalPlayer():GetRank() == "2nd") then
draw.DrawText( ""..(tab[1].Play:Frags()).."", "Quaketext",(ScrW()-ScrW()/5)+((ScrW()/6)/3)+40,(ScrH()-ScrH()/5)+10, Color(255,255,255,255 ), TEXT_ALIGN_LEFT )
draw.DrawText( ""..(LocalPlayer():Frags()).."", "Quaketext",(ScrW()-ScrW()/5)+((ScrW()/6)/3)+150,(ScrH()-ScrH()/5)+10, Color(255,255,255,255 ), TEXT_ALIGN_LEFT )
end


end

function GM:CrossHair()

		surface.SetDrawColor( 255, 0, 0, 255)
		surface.DrawRect((ScrW() / 2),(ScrH() /2 )-5,1,11)
		surface.DrawRect((ScrW() / 2) - 5,(ScrH() /2 ),11,1)
		surface.DrawCircle( (ScrW() / 2),(ScrH() /2 ), 15, Color(255, 0, 0, 255) )

end

function GM:SetupHud()

if(!LocalPlayer():Alive()) then return end
if(!IsValid(LocalPlayer():GetActiveWeapon())) then return end
//von links nach rechts ^^
//Ammo
if(CurTime() > LocalPlayer():GetActiveWeapon():GetNextPrimaryFire()) then
draw.DrawText( ""..(LocalPlayer():GetActiveWeapon():Clip1()).."", "QuakeHud", 15, ScrH()-110, Color(225,215,0,255 ), TEXT_ALIGN_LEFT )
else
draw.DrawText( ""..(LocalPlayer():GetActiveWeapon():Clip1()).."", "QuakeHud", 15, ScrH()-110, Color(80,80,80,255 ), TEXT_ALIGN_LEFT )
end
//Ammortype
//pic
//Health
draw.DrawText( ""..(LocalPlayer():Health()).."", "QuakeHud", ScrW()/4+10, ScrH()-110, Color(225,215,0,255 ), TEXT_ALIGN_LEFT )
//Face
//pic
//Armor
draw.DrawText( ""..(LocalPlayer():Armor()).."", "QuakeHud", ScrW()/2+30, ScrH()-110, Color(225,215,0,255 ), TEXT_ALIGN_LEFT )
//Armortype
//pic

end

function GetPosbyBone( ply, bone )//BONE_HEAD


local bonepos = ply:LookupBone(bone)
local pos = ply:GetBonePosition(bonepos)
return pos

end


function DrawsPlayerSprite( um )

 Killer = um:ReadEntity()
 Fl = um:ReadShort() 
 Bool = true

end

usermessage.Hook("KillSprite",DrawsPlayerSprite)

function DrawStreak(arg1,arg2)
local v = arg1
local flag = arg2
if(!Bool) then return end
if(v == LocalPlayer() ) then
	else
			if(  v:Alive()  ) then
			LocalPlayer():ChatPrint(v:GetName() .. " has killed with streak" )
				if( flag == EF_AWARD_EXCELLENT  ) then
					local HeadPos = GetPosbyBone(v,"ValveBiped.Bip01_Head1"):ToScreen()
						surface.SetMaterial(Material("VGUI/medals/medalexcellent.png"))
						surface.SetDrawColor(255,255,255,math.sin(CurTime() * 1.5) * 255)
						surface.DrawTexturedRect( HeadPos.x-20,HeadPos.y-100, 64 , 64 )
						if(math.sin(CurTime() * 1.5) * 255 <= 5) then Bool = false end	
				elseif( flag == EF_AWARD_GAUNTLET ) then

				elseif(flag == EF_AWARD_CAP ) then

				elseif( flag == EF_AWARD_IMPRESSIVE  ) then
					local HeadPos = GetPosbyBone(v,"ValveBiped.Bip01_Head1"):ToScreen()
						surface.SetMaterial(Material("VGUI/medals/medal_impressive.png"))
						surface.SetDrawColor(255,255,255,math.sin(CurTime() * 1.5) * 255)
						surface.DrawTexturedRect( HeadPos.x-20,HeadPos.y-100, 64 , 64 )
						if(math.sin(CurTime() * 1.5) * 255 <= 5) then Bool = false end
				elseif( flag == EF_AWARD_DEFEND ) then

				elseif( flag == EF_AWARD_ASSIST ) then

				elseif( flag == EF_AWARD_DENIED ) then

				elseif( flag == EF_AWARD_NONE ) then
			end
		end
	end

end

function Leads( um )

local ply = um:ReadEntity()
	if( ply:GetRank() == "none" ) then
		if( Oldrank == "1st") then
			surface.PlaySound("feedback/lostlead.wav")
		end
		Oldrank = ply:GetRank()
	elseif( ply:GetRank() == "3rd" ) then
		if( Oldrank == "1st") then
			// lost the lead
			surface.PlaySound("feedback/lostlead.wav")
		end
		Oldrank = ply:GetRank()
	elseif( ply:GetRank() == "2nd" and Oldrank != "2nd" ) then
		if( Oldrank == "1st") then
			// lost the lead
			surface.PlaySound("feedback/lostlead.wav")
		else
			// tied for the lead
			surface.PlaySound("feedback/tiedlead.wav")
		end

		Oldrank = ply:GetRank()
	elseif( ply:GetRank() == "1st" ) then
		if( Oldrank == "3rd" or Oldrank == "2nd") then
			// taken the lead sound 
			surface.PlaySound("feedback/takenlead.wav")
		end
		Oldrank = ply:GetRank()
	end


end

usermessage.Hook("leader",Leads)

function GM:AddAwardHud( attacker, victim, flag )
if(BOOL) then 
	if( flag == EF_AWARD_EXCELLENT ) then
		 local a = 0
		local b = -1

		for i = 1, LocalPlayer():GetFlagCount() do
			if(self:Delay(i)) then
			a = a + 1
				surface.SetMaterial(Material("VGUI/medals/medalexcellent.png"))
				surface.SetDrawColor(255,255,255,math.sin(CurTime() * 1.5) * 255)
				surface.DrawTexturedRect( ScrW()/2 - (a)*66, ScrW()/13, 64 , 64 )
			elseif(!self:Delay(i)) then
			b = b + 1
				surface.SetMaterial(Material("VGUI/medals/medalexcellent.png"))
				surface.SetDrawColor(255,255,255,math.sin(CurTime() * 1.5) * 255)
				surface.DrawTexturedRect( ScrW()/2 + (b)*66, ScrW()/13, 64 , 64 )
			end
							if(i == 1) then
		Msg("".. i .. " \n")
		end
		end
		if(LocalPlayer():GetPlayedSound() and flag != EF_AWARD_IMPRESSIVE ) then -- LocalPlayer():SoundPlayed();LocalPlayer.soundPlayed == true .....
		else
		surface.PlaySound("feedback/excellent.wav")
		PlayerData[1].SoundPlayed = true
		end
	elseif( flag == EF_AWARD_GAUNTLET ) then

	elseif( flag == EF_AWARD_CAP ) then

	elseif( flag == EF_AWARD_IMPRESSIVE ) then
			local a = 0
		local b = -1
		for i = 1, LocalPlayer():GetFlagCount2() do
			if(self:Delay(i)) then
			a = a + 1
				surface.SetMaterial(Material("VGUI/medals/medal_impressive.png"))
				surface.SetDrawColor(255,255,255,math.sin(CurTime() * 1.5) * 255)
				surface.DrawTexturedRect( ScrW()/2 - (a)*66, ScrW()/13, 64 , 64 )
			elseif(!self:Delay(i)) then
			b = b + 1
				surface.SetMaterial(Material("VGUI/medals/medal_impressive.png"))
				surface.SetDrawColor(255,255,255,math.sin(CurTime() * 1.5) * 255)
				surface.DrawTexturedRect( ScrW()/2 + (b)*66, ScrW()/13, 64 , 64 )
			end
		end
		if(LocalPlayer():GetPlayedSound() and flag == EF_AWARD_IMPRESSIVE  ) then --if(CurTime() > LocalPlayer():GetNWFloat("lastkill") + 4) then
		else
		surface.PlaySound("feedback/impressive.wav")
		PlayerData[1].SoundPlayed = true
		end
	elseif( flag == EF_AWARD_DEFEND ) then

	elseif( flag == EF_AWARD_ASSIST ) then

	elseif( flag == EF_AWARD_DENIED ) then

	elseif( flag == EF_AWARD_NONE ) then
	
	end

		if(attacker:GetRank() == "none") then
		draw.DrawText( "You fragged "..victim.."\n".." "..attacker:Frags().." ", "Quake1", (ScrW()/2), (ScrH()/6), Color(255,255,255,math.sin(CurTime() * 1.5) * 255 ), TEXT_ALIGN_CENTER )
		else
		draw.DrawText( "You fragged "..victim.."\n" .. "is on " .. attacker:GetRank() .. " place "..attacker:Frags().." ", "Quake1", (ScrW()/2), (ScrH()/6), Color(255,255,255,math.sin(CurTime() * 1.5) * 255 ), TEXT_ALIGN_CENTER )
		end
	end

end
--[[---------------------------------------------------------
   Name: gamemode:HUDShouldDraw( name )
   Desc: return true if we should draw the named element
-----------------------------------------------------------]]
local hud = {"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}
function GM:HUDShouldDraw(name)
   for k, v in pairs(hud) do
      if name == v then return false end
   end

   return true
end
/*
function meta:GetPlayedSound()
function meta:GetRank()
function meta:GetFlag()
function meta:GetFlagCount()
function meta:GetLastKill()
function meta:GetLastVictim()

*/
--[[---------------------------------------------------------
   Name: gamemode:HUDPaint( )
   Desc: Use this section to paint your HUD
-----------------------------------------------------------]]
function GM:HUDPaint()
	GAMEMODE:HUDDrawTargetID()
	GAMEMODE:HUDDrawPickupHistory()
	GAMEMODE:DrawDeathNotice( 0.85, 0.04 )
	GAMEMODE:SmallStats()
	GAMEMODE:SetupHud()
	GAMEMODE:CrossHair()
	DrawStreak(Killer,Fl)
	if( LocalPlayer():GetFlag() == EF_AWARD_NONE and CurTime()>=LocalPlayer():GetLastKill()+ REWARD_SPRITE_TIME ) then
		//DO NOTHING
	elseif( LocalPlayer():GetFlag() == EF_AWARD_EXCELLENT and CurTime()<=LocalPlayer():GetLastKill()+ REWARD_SPRITE_TIME) then

	self:AddAwardHud( LocalPlayer(), LocalPlayer():GetLastVictim(), EF_AWARD_EXCELLENT )
	

	
	elseif( LocalPlayer():GetFlag() == EF_AWARD_IMPRESSIVE and CurTime()<=LocalPlayer():GetLastKill()+ REWARD_SPRITE_TIME ) then
		self:AddAwardHud( LocalPlayer(), LocalPlayer():GetLastVictim(), EF_AWARD_IMPRESSIVE )

	


	end



end

--[[---------------------------------------------------------
   Name: gamemode:HUDPaintBackground( )
   Desc: Same as HUDPaint except drawn before
-----------------------------------------------------------]]
function GM:HUDPaintBackground()
end


function HudDisplays()


end